<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-08-14
  Time: 10:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <style>
        table tr td {
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
<%
if (request.getAttribute("status") ==  null){
    response.sendRedirect("CardListServlet");
}
%>
<a href="card_Inset.jsp">新增</a>
<table>
    <tr>
        <td>持卡人姓名</td>
        <td>持卡人身份证</td>
        <td>启用状态</td>
        <td>办卡日期</td>
        <td>状态</td>
    </tr>
    <c:forEach items="${requestScope.list}" var="card">
        <tr>
            <td>${card.userName}</td>
            <td>${card.idNumber}</td>
            <c:if test="${card.status == 0}">
                <td onclick="Up(${card.id},${card.status})">禁用</td>
            </c:if>
            <c:if test="${card.status == 1}">
                <td onclick="Up(${card.id},${card.status})">启用</td>
            </c:if>
            <td>${card.createDate}</td>
        </tr>
    </c:forEach>
</table>

<script>
function Up(id,status){
    var sf = confirm("确定要修改吗？")
    if (sf == true){
        $.get("${pageContext.request.contextPath}/CardUpdateServlet",{"id":id,"status":status},function (data){
            if (data>0) {
                alert("修改成功！")
                location.href="CardListServlet"
            }else {
                alert("修改失败！")
            }
        })
    }
}
</script>
</body>
</html>
